﻿Imports Aricie.DNN.UI.Controls
Imports Lucene.Net.Search
Imports Aricie.ComponentModel
Imports Aricie.DNN.Modules.LuceneSearch.Business


Namespace Aricie.DNN.Modules.LuceneSearch.UI.FilteringControls
    ''' <summary>
    ''' Tentative de clarifier comment fonctionnent les filtres
    ''' </summary>
    ''' <remarks></remarks>
    Public MustInherit Class FilteringControl
        Inherits AricieUserControlBase
        Implements IFilteringControl

        Public Overridable Property Fields As String
        Public ReadOnly Property FieldsList As IList(Of String)
            Get
                Return Fields.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
            End Get
        End Property

        Public MustOverride Property Enabled As Boolean Implements IFilteringControl.Enabled

        Public Event FilterChanged(ByVal sender As Object, ByVal e As GenericEventArgs(Of Business.LuceneFilterQuery)) Implements IFilteringControl.FilterChanged
        Protected Sub SignalFilterChanged()
            RaiseEvent FilterChanged(Me, New GenericEventArgs(Of LuceneFilterQuery)(GetFilter()))
        End Sub

        Public MustOverride Function HasFilter() As Boolean Implements IFilteringControl.HasFilter
        Public Overridable Function GetFilter() As Business.LuceneFilterQuery Implements IFilteringControl.GetFilter
            Dim result As New LuceneFilterQuery()
            result.FilterQuery = SetFilter()
            Return result
        End Function

        Public Overridable Function ParseFilter(objFilter As Business.LuceneFilterQuery) As Boolean Implements IFilteringControl.ParseFilter
            Return ReadFilter(objFilter.FilterQuery)
        End Function


        Public MustOverride Function SetFilter() As Query
        Public MustOverride Function ReadFilter(q As Query) As Boolean
    End Class
End Namespace